
@extends('Admin.common.header')

<!-- 1.添加meta csrf_token -->
<meta name="csrf-token" content="{{ csrf_token() }}">  

<body style="background-color:#7A7A7A;">


<div style="margin-top:10%;color:#FFFFFF;width:98%;margin-bottom:70px;" class="form-horizontal">
	
	<!-- 页面标记  -->
	<h3 style='color:white;margin-left:154px;margin-top:-30px;color:#D1EEEE' >		
		{{ $title or '' }}
	</h3>
	
	<!-- 添加后台用户表单  -->
	<!-- 人员权限 -->
	<div style="margin-left:12.7%;" class="radio">
		<span style="font-weight:bold;">权限</span>
	@if( !isset($admin_info) )
		<label style="margin-left:30px;">
			<input type="radio" checked  name="type" value="2" >普通
		</label>
		<label>
			<input type="radio"   name="type" value="1" >超级
		</label>
	@else
		@if( $admin_info->type == '1' )
		<label style="margin-left:30px;" >
			<input type="radio"  name="type" value="2" > 普通
		</label>
		<label >
			<input type="radio" checked  name="type" value="1" > 超级
		</label>
		@elseif( $admin_info->type == '2' )
		<label style="margin-left:30px;" >
			<input type="radio" checked  name="type" value="2" >普通
		</label>
		<label>
			<input type="radio"   name="type" value="1" >超级
		</label>
		@endif
	@endif
	</div>
	
	<br>
	<div  class="form-group">
	  <label class="col-sm-2 control-label">名字</label>
	  <div class="col-sm-10">
	    <input style="width:300px;" type="text" name="name" value="{{ $admin_info->name or '' }}" class="form-control"  placeholder="用户名">
	  </div>
	</div>



	<!-- 部门 -->
	<div style="margin-left:12.7%;" class="radio">
		<span style="font-weight:bold;">部门</span>
		@if( isset($admin_info) )
			@foreach ($all_department as $department)
			<label style="margin-left:27px;" >
				@if( $department->id == $admin_info->department_id )
					<input type="radio" name="department_id" id="blankRadio1" value="{{ $department->id }}" checked />{{ $department->name }}
				@else
					<input type="radio" name="department_id" id="blankRadio1" value="{{ $department->id }}" />{{ $department->name }}
				@endif
			</label>	
			@endforeach
		@else
			@foreach ($all_department as $department)
			<label style="margin-left:27px;" >
				<!-- 默认选中 1 技术部 -->
				@if( $department->id == 1 )
					<input type="radio" name="department_id" id="blankRadio1" value="{{ $department->id }}" checked />{{ $department->name }}
				@else
					<input type="radio" name="department_id" id="blankRadio1" value="{{ $department->id }}" />{{ $department->name }}
				@endif
			</label>	
			@endforeach
		@endif		
	</div>
	<br>
	
	<!-- 性别 -->
	<div class="form-group">
	<!-- <div class="col-sm-offset-2 col-sm-10"> -->
	<label class="col-sm-2 control-label">性别</label>&nbsp;&nbsp;&nbsp;
	@if( !isset($admin_info) )
		<!-- 默认选中 男 -->
		<label class="radio-inline">
			<input type="radio" checked name="sex" id="inlineRadio1"  value="1"> 男
		</label>
		<label class="radio-inline">
			<input type="radio"  name="sex" id="inlineRadio2" value="2"> 女
		</label>
	@else
		@if( $admin_info->sex == '1')
		<label class="radio-inline">
			<input type="radio" checked name="sex" id="inlineRadio1"  value="1"> 男
		</label>
		<label class="radio-inline">
			<input type="radio"  name="sex" id="inlineRadio2" value="2"> 女
		</label>
		@elseif( $admin_info->sex == '2')
		<label class="radio-inline">
			<input type="radio"  name="sex" id="inlineRadio1"  value="1"> 男
		</label>
		<label class="radio-inline">
			<input type="radio" checked name="sex" id="inlineRadio2" value="2"> 女
		</label>
		@endif
	@endif
	</div>
	

	<!-- 密码 -->
	<div  class="form-group">
	    <label class="col-sm-2 control-label">密码</label>
		@if( isset($admin_info) )
	    <div class="col-sm-10">
	      <input style="width:300px;" type="password" name="password" value="{{ $admin_info->password }}" class="form-control" id="inputPassword3" placeholder="密码" disabled />
	    </div>
	    @else
	    <div class="col-sm-10">
	       <input style="width:300px;" type="password" name="password" value="" class="form-control" id="inputPassword3" placeholder="密码">
	    </div>
	    @endif 
	</div>
	
	
	<div class="form-group">
		<label class="col-sm-2 control-label">确认密码</label>
		<div class="col-sm-10">
		@if( isset($admin_info) )
			<input style="width:300px;" type="password" name="repassword" value="{{ $admin_info->password }}" class="form-control" id="inputPassword3" placeholder="确认密码" disabled >
		@else 
			<input style="width:300px;" type="password" name="repassword" value="" class="form-control" id="inputPassword3" placeholder="确认密码">
		@endif
		</div>
	</div>
	
	<!-- 手机号 -->
	<div  class="form-group">
		<label class="col-sm-2 control-label">手机号</label>
		<div class="col-sm-10">
			<input style="width:300px;" type="text" name="phone" value="{{ $admin_info->phone or '' }}" class="form-control" id="inputEmail3" placeholder="手机号">
		</div>
	</div>
	
	<!-- 背景图片 -->
	<div style="position:absolute;left:58%;top:26%;">
		<img src="{{ asset('./images/logo.png') }}" alt="">
	</div>
	<br>

	<!-- 1.模态框 不要动 -->
	@if( isset($admin_info) )
		<button  style="width:25%;margin-left:15%;" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-danger">编辑</button>
	@else 
		<button  style="width:25%;margin-left:15%;" data-toggle="modal" data-target=".bs-example-modal-sm" class="btn btn-danger">新增</button>
	@endif

	<div  class="form-group" style="margin-top:2%;">
		<a href="{{ url('/admin') }}" style="width:24.6%;margin-left:15.8%;" class="btn btn-success">
			列表
		</a>
	</div>
	
	<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
	  <div class="modal-dialog modal-sm" role="document" id='show_info'  style="margin-top:80px;margin-left:570px;">
	  </div>
	</div>

</div>

<div id="admin" adminid="{{ $admin_info->id or '' }}" ></div>

<script src=" {{ asset('./js/jquery-1.8.3.min.js') }} "></script>
<script>
	<!-- 2.设置全局ajax选项 -->
	$.ajaxSetup({
		headers: {
			'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
		}
	});
	var _token = $('meta[name="csrf-token"]').attr('content');
	
	
	$(function(){
		
		// 执行 创建 编辑 员工
		var admin_id = $("#admin").attr('adminid');

		$("button").click(function(){
			var type	=	$("input[name='type']:checked").val();
			var name	=	$("input[name='name']").val();
			var department_id	=	$("input[name='department_id']:checked").val();
			var sex		=	$("input[name='sex']:checked").val();
			var password	=	$("input[name='password']").val();
			var repassword	=	$("input[name='repassword']").val();
			var phone	=	$("input[name='phone']").val();

			if( admin_id )
				{
					// 编辑
					var url ="{{ url('/admin/store') }}"+'/'+admin_id;
				}else
				{
					// 创建
					var url ="{{ url('/admin/store') }}";
				}
			
			$.ajax({
				type:"post",
				url:url,
				data:{type:type,name:name,department_id:department_id,sex:sex,password:password,repassword:repassword,phone:phone,_token:_token},
				async:true,    					
				dataType:"json",
				success:function(back){
					// 2.模态框 不要动
					$('#show_info').html( '' );
					$('#show_info').html( back['show_info'] );
					location.reload();
				}
			});
		});
	});
</script>
</body>
@extends('Admin.common.footer')